home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Ken Long / CircularWDEF / Ori-circularWDEF.c < prev    next >
Encoding:
Text File  |  1994-12-04  |  5.7 KB  |  269 lines  |  [TEXT/KAHL]

  1. /* Optional:
  2.  * pascal long myWindowWDEF (int varCode,
  3.                              WindowPeek theWindow,
  4.                              int message,
  5.                              long param)
  6. */
  7.  
  8. pascal long main (int varCode,
  9.                         WindowPeek theWindow,
  10.                                 int message, long param)
  11. {
  12.     typedef Rect *RPtr;
  13.     Rect r, rclose[4], rgrow, rtitle;
  14.     int i, j, k;
  15.     Point p;
  16.     GrafPtr temp;
  17.     PenState pnState;
  18.     RgnHandle hstructure, hcontent, frame, htitle;
  19.     Pattern pat;
  20.     Str255 title;
  21.     
  22.     GetPort (&temp);
  23.     SetPort ((GrafPtr)theWindow);
  24.     
  25.     r = (*((GrafPtr)theWindow)).portRect;
  26.     i = r.right - r.left;
  27.     j = r.bottom - r.top;
  28.     
  29.     if (i > j)
  30.         i = j;
  31.     r.left = 0;
  32.     r.top = 0;
  33.     LocalToGlobal (& (r));
  34.     SetPort (temp);
  35.     r.bottom = r.top + i;
  36.     r.right = r.left + i;
  37.     
  38.     SetRect (&rclose[0], r.left +  3, r.top + i / 2 - 6,
  39.                          r.left + 14, r.top + i / 2 + 5);
  40.                         
  41.     SetRect (&rclose[1], r.right - 14, r.top + i / 2 -6,
  42.                          r.right -  3, r.top + i / 2 + 5);
  43.                         
  44.     SetRect (&rclose[2], r.left + i / 2 - 6, r.top + 3,
  45.                          r.left + i / 2 + 5, r.top + 14);
  46.                         
  47.     SetRect (&rclose[3], r.left + i / 2 - 6, r.bottom -14,
  48.                          r.left + i / 2 + 5, r.bottom -3);
  49.                      
  50.     rgrow.right = r.left + i / 2 + ((i / 2) * 10) / 14;
  51.     rgrow.bottom =  r.top  + i / 2 + ((i / 2) * 10) / 14;
  52.     rgrow.left = rgrow.right - (9 * 141) / 100;
  53.     rgrow.top = rgrow.bottom - (9 * 141) / 100;
  54.     for (k = 0; k < 256; k++)
  55.         title[k] = * (*((*theWindow).titleHandle) + k);
  56.         title == "\p";
  57.     j = StringWidth (&title) / 2 + 15;
  58.     rtitle.left = r.left + i / 2 - j;
  59.     rtitle.right = rtitle.left + j + j;
  60.     
  61.     if (varCode & 0x0008)
  62.     {
  63.         rtitle.top = r.top;
  64.         rtitle.bottom = r.top + 16;
  65.     }
  66.     else 
  67.         {
  68.             rtitle.bottom = r.bottom;
  69.             rtitle.top = r.bottom - 16;
  70.     }
  71.     p.v = HiWord (param);
  72.     p.h = LoWord (param);
  73.     hstructure = (*theWindow).strucRgn;
  74.     hcontent = (*theWindow).contRgn;
  75.     switch (message)
  76.     {
  77.         case 0: if ((*theWindow).visible)
  78.         {
  79.             if (param == 0L)
  80.             {
  81.                 GetPenState (&pnState);
  82.                 PenSize (18, 18);
  83.                 PenMode (patBic);
  84.                 FrameOval (&r);
  85.                 SetPenState (&pnState);
  86.                 if (((*theWindow).hilited) && (varCode & 0x0004))
  87.                 {
  88.                     pat[0] = 0xF8;
  89.                     pat[1] = 0x74;
  90.                     pat[2] = 0x22;
  91.                     pat[3] = 0x47;
  92.                     pat[4] = 0x8F;
  93.                     pat[5] = 0x17;
  94.                     pat[6] = 0x22;
  95.                     pat[7] = 0x71;
  96.                     
  97.                     FrameOval (&r);
  98.                     InsetRect (&r, 1, 1);
  99.                     FrameOval (&r);
  100.                     InsetRect (&r, 1, 1);
  101.                     frame = NewRgn ();
  102.                     OpenRgn ();
  103.                     FrameOval (&r);
  104.                     InsetRect (&r, 13, 13);
  105.                     FrameOval (&r);
  106.                     CloseRgn (frame);
  107.                     FillRgn (frame, &pat);
  108.                     DisposeRgn (frame);
  109.                     FrameOval (&r);
  110.                     InsetRect (&r, 1, 1);
  111.                     FrameOval (&r);
  112.                 }
  113.                 else
  114.                     {
  115.                         FrameOval (&r);
  116.                         InsetRect (&r, 3, 3);
  117.                         if ((*theWindow).hilited)
  118.                             for (i = 0; i < 6; i++)
  119.                             {
  120.                                 FrameOval (&r);
  121.                                 InsetRect (&r, 2, 2);
  122.                             }
  123.                         else
  124.                             InsetRect (&r, 12, 12);
  125.                             InsetRect (&r, 1, 1);FrameOval (&r);
  126.                 }
  127.                 if (((*theWindow).hilited) && ((*theWindow).goAwayFlag))
  128.                 {
  129.                     for (i = 0; i < 4; i++)
  130.                     {
  131.                         EraseRect (&rclose[i]);
  132.                         FrameRect (&rclose[i]);}
  133.                     }
  134.                     if (((*theWindow).hilited) && ((varCode & 0x0002) == 0))
  135.                     {
  136.                         EraseRect (&rgrow);
  137.                         FrameRect (&rgrow);
  138.                     }
  139.                     if (varCode & 0x0001)
  140.                     {
  141.                         EraseRect (&rtitle);
  142.                         FrameRect (&rtitle);
  143.                         if ((*theWindow).hilited)
  144.                         {
  145.                             InsetRect (&rtitle, 1, 1);
  146.                             FrameRect (&rtitle);
  147.                             InsetRect (&rtitle, -1, -1);
  148.                             MoveTo (rtitle.left + 15, rtitle.top + 13);
  149.                             DrawString (&title);
  150.                         }
  151.                 }
  152.             }
  153.             else
  154.                 if (param == 4L)
  155.                 {
  156.                     GetPenState (&pnState);
  157.                     PenMode (patXor);
  158.                     for (i = 0; i < 4; i++)
  159.                         if ((i == 2) &&
  160.                              (varCode & 1) &&
  161.                              (varCode & 8));
  162.                         else
  163.                             if ((i == 3) &&
  164.                                  (varCode & 1) && !
  165.                                  (varCode & 8));
  166.                         else
  167.                             {
  168.                                 MoveTo (rclose[i].left+2, rclose[i].top+2);
  169.                                 Line (6, 6);
  170.                                 MoveTo (rclose[i].left+2, rclose[i].bottom-3);
  171.                                 Line (6, -6);
  172.                                 MoveTo (rclose[i].left+1, rclose[i].top + 5);
  173.                                 Line (8, 0);
  174.                                 MoveTo (rclose[i].left+5, rclose[i].top+1);
  175.                                 Line (0, 8);
  176.                                 InsetRect (&rclose[i], 4, 4);
  177.                                 EraseRect (&rclose[i]);
  178.                         }
  179.                     SetPenState (&pnState);
  180.                 }
  181.             }
  182.             return (0L);
  183.         break;
  184.         
  185.         case 1:
  186.             if (PtInRgn (p, hcontent))
  187.                 return (1L);
  188.             else
  189.                 if ((PtInRect (p, &rclose[0])) &&
  190.                      ((*theWindow).goAwayFlag)  &&
  191.                      ((*theWindow).hilited))
  192.                 return (4L);
  193.             else
  194.                 if ((PtInRect (p, &rclose[1])) &&
  195.                      ((*theWindow).goAwayFlag)  &&
  196.                      ((*theWindow).hilited))
  197.                 return (4L);
  198.             else
  199.                 if ((PtInRect (p, &rclose[2])) &&
  200.                      ((*theWindow).goAwayFlag)  &&
  201.                      ((*theWindow).hilited)    &&
  202.                      (! ((varCode & 1)        &&
  203.                      (varCode & 8))))
  204.                 return (4L);
  205.             else
  206.                 if ((PtInRect (p, &rclose[3])) &&
  207.                      ((*theWindow).goAwayFlag)  &&
  208.                      (! ((varCode & 1)        &&
  209.                     ! (varCode & 8)))        &&
  210.                      ((*theWindow).hilited))
  211.                 return (4L);
  212.             else
  213.                 if ((PtInRect (p, &rgrow))    &&
  214.                      ((varCode & 0x0002) == 0)  &&
  215.                      ((*theWindow).hilited))
  216.                 return (3L);
  217.             else
  218.                 if (PtInRgn (p, hstructure))
  219.                     return (2L);
  220.             else
  221.                 return (0L);
  222.         break;
  223.         
  224.         case 2:
  225.             SetEmptyRgn (hstructure);
  226.             OpenRgn ();
  227.             FrameOval (&r);
  228.             CloseRgn (hstructure);
  229.             if (varCode & 0x0001)
  230.             {
  231.                     htitle = NewRgn ();
  232.                     RectRgn (htitle, &rtitle);
  233.                     UnionRgn (hstructure, htitle,
  234.                             hstructure);
  235.                     DisposeRgn (htitle);
  236.             }
  237.             InsetRect (&r, 18, 18);
  238.             SetEmptyRgn (hcontent);
  239.             OpenRgn ();
  240.             FrameOval (&r);
  241.             CloseRgn (hcontent);
  242.         break;
  243.         
  244.         case 3:
  245.             return (0L);
  246.         break;
  247.     
  248.         case 4:
  249.             return (0L);
  250.         break;
  251.     
  252.         case 5:
  253.             r = * (RPtr)param;
  254.             i = r.right - r.left;
  255.             j = r.bottom - r.top;
  256.             if (i > j) i = j;
  257.             r.right = r.left + i;
  258.             r.bottom = r.top + i;
  259.             FrameOval (&r);
  260.             return (0L);
  261.         break;
  262.     
  263.         case 6:
  264.             return (0L);
  265.         break;
  266.     }
  267. }
  268.  
  269.